<%@page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
<!DOCTYPE html>
<!-- saved from url=(0054)http://om.cwewater.com:7000/Admin/UpdatePassword/Index -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="resources/updatepwd/bootstrap.min.css" rel="stylesheet">
    <link href="resources/updatepwd/font-awesome.css" rel="stylesheet">
    <link href="resources/updatepwd/animate.css" rel="stylesheet">
    <link href="resources/updatepwd/style.css" rel="stylesheet">
    <script src="resources/updatepwd/jquery-1.9.1.min.js"></script>
    <title>修改密码</title>
</head>
<body class="gray-bg">
<div class="passwordBox animated fadeInDown">
    <div class="row">
        <div class="col-md-12">
            <div class="ibox-content">
                <h2 class="font-bold">修改密码</h2>
                <p>
                    此操作将会影响所有业务系统.请谨慎操作.
                </p>
                <div class="row">
                    <div class="col-lg-12">

                        <div class="form-group">
                            <input id="username" type="text" class="form-control" placeholder="请输入工号" required="">
                        </div>


                        <div class="form-group">
                            <input id="oldpass" type="text" class="form-control" placeholder="请输入手机号" required="">
                        </div>
                        <div class="form-group">
                            <%--<input id="verifycode" type="text" class="form-control" placeholder="请输入验证码" required="">--%>
                            <div class="input-group">
                                <input type="text" id="verifycode" class="form-control" placeholder="请输入验证码">
                                <span class="input-group-btn">
                                    <button id="sendcode" class="btn btn-primary" type="button">发送验证码<span id="timer"></span></button>
                                </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <input id="newpass1" type="password" class="form-control" placeholder="请输入新密码" required="">
                        </div>


                        <div class="form-group">
                            <input id="newpass2" type="password" class="form-control" placeholder="再次输入新密码" required="">
                        </div>


                        <button id="save" type="button" class="btn btn-primary block full-width m-b">修改</button>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-md-6">
            Copyright CWEWATER
        </div>
        <div class="col-md-6 text-right">
            <small>© 2019-2020</small>
        </div>
    </div>
</div>


<script>
    var headers={
        Authorization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mg4Xpk77mjqXnrqHnkIblkZgiLCLns7vnu5_nrqHnkIblkZgiLCLmma7pgJrnlKjmiLciLCLlj5HmlofnrqHnkIblkZgiXSwiaWF0IjoxNTU2MTc2NTA2LCJqdGkiOiIwNmFhYmY5YS1iNGQzLTQwZWMtYWIxMS1lNzAyOTMzZmY5YzUifQ.dWEt0KQQ9kSvoU-oEaAraPcWbvdDtYGd9AJkbfFSvOU7m9aQUWtF0HPCgQVpkYdB7XgVYvc-CRewa4_tr1_IakixOHh2EDH1Yt8mgq4py68_vAXBk2Q5G8FdtX7Z5rJRNPilP3oeaDbXH-LkwJ4URbX4H5414V0R6rtFapxwT6CTnMaFiep8t_nz7e863GNBNQ0LRIukMhT9UmCzPpijNxAzDspDjRXkR8r0BqMca0nXNpub0csBDMn4fFy39KJnwgyWZdbh2pH4WRg7an8MCgnH8jlgDZi-Jvf1KoX4eGZaQf-UEYyOeLnTrhEyiHjAzNYerR4TmQIsxMiyTOMBQg"
    }
    var Time=60;
    function timer(){
        Time=60;
        $("#sendcode").attr("disabled","disabled");
        var intId=setInterval(function () {
            $("#timer").text("("+Time+")");
            Time--;
            if(Time<=0){
                Time=0;
                $('#sendcode').removeAttr("disabled");
                clearInterval(intId);
                $("#timer").text("");
            }
        },1000)

    }

    $("#sendcode").bind("click", function () {
        if (!$("#username").val()) {
            alert("工号不能为空");
            return;
        }

        if (!$("#oldpass").val()) {
            alert("手机号不能为空");
            return;
        }
        $.ajax({
            headers: headers,
            type: "POST",
            url: "http://dm.cwewater.com:8806/services/api/assignverificationcode",
            contentType: "application/json", //如果提交的是json数据类型，则必须有此参数,表示提交的数据类型
            data:   JSON.stringify({
                "appCode": "WE.EnterprisePortal",
                "phone": $("#oldpass").val().trim(),
                "userCode": $("#username").val().trim()
            }),
            success: function (jsonResult) {
                if(jsonResult.success){
                    alert("发送成功!");
                    timer();
                }else{
                    if(jsonResult.error){
                        alert("发送失败! "+jsonResult.error.message||" ");
                    }else {
                        alert("发送失败!");
                    }
                }
            },
            error: function (data) {
                alert("发送失败!")
            }
        });

    });

    $("#save").bind("click", function () {
        if (!$("#username").val()) {
            alert("工号不能为空");
            return;
        }

        if (!$("#oldpass").val()) {
            alert("手机号不能为空");
            return;
        }
        if (!$("#verifycode").val()) {
            alert("验证码不能为空");
            return;
        }

        if (!$("#newpass1").val()) {
            alert("新密码不能为空");
            return;
        }

        if (!$("#newpass2").val()) {
            alert("新密码不能为空");
            return;
        }

        if ($("#newpass1").val() != $("#newpass2").val()) {
            alert("两次新密码不一致");
            return;
        }

        if (confirm('确定要修改密码么?')) {
            $.ajax({
                headers: headers,
                type: "POST",
                url: "http://dm.cwewater.com:8806/services/api/editpassword",
                contentType: "application/json", //如果提交的是json数据类型，则必须有此参数,表示提交的数据类型
                data: JSON.stringify({
                "newPassword": $("#newpass1").val().trim(),
                "phone":$("#oldpass").val().trim(),
                "userCode": $("#username").val().trim(),
                "verificationCode": $("#verifycode").val()
                }),
                success: function (jsonResult) {
                    if(jsonResult.success){
                        alert("修改成功!");
                        window.location.href="./login"
                    }else{
                        if(jsonResult.error){
                            alert("修改失败! "+jsonResult.error.message||" ");
                        }else {
                            alert("修改失败!");
                        }
                    }
                },
                error: function (data) {
                    alert("修改失败!")
                }
            });
        }
    });
</script>
<div id="Pinbox-extension-installed"></div></body></html>
